package com.example.demo2.controller;

import com.example.demo2.generator.entity.PlanList;
import com.example.demo2.generator.entity.R;
import com.example.demo2.generator.entity.WlManager;
import com.example.demo2.generator.service.WlManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 物料管理(WlManager)表控制层
 *
 * @author makejava
 * @since 2024-09-26 23:40:35
 */
@Api(value = "货物Controller",tags = "货物信息接口")
@RestController
@RequestMapping("/wlManager")
public class WlManagerController {
    /**
     * 服务对象
     */
    @Resource
    private WlManagerService wlManagerService;

    /**
     * 分页查询
     *
     * @param wlManager 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<WlManager>> queryByPage(WlManager wlManager, PageRequest pageRequest) {
        return ResponseEntity.ok(this.wlManagerService.queryByPage(wlManager, pageRequest));
    }
    @ApiOperation("查找货物信息")
    @GetMapping("/query")
    public R queryAll(WlManager wlManager){
        List<WlManager> query = wlManagerService.query(wlManager);
        return  R.ok("查询成功",query);
    }


    /**
     * 新增数据
     *
     * @param wlManager 实体
     * @return 新增结果
     */
    @ApiOperation("添加货物信息")
    @PostMapping()
    public R add(@RequestBody WlManager wlManager) {
        return R.ok(this.wlManagerService.insert(wlManager));
    }

    /**
     * 编辑数据
     *
     * @param wlManager 实体
     * @return 编辑结果
     */
    @ApiOperation("更新数据")
    @PostMapping("/update")
    public R edit(WlManager wlManager) {
        return R.ok(this.wlManagerService.update(wlManager));
    }

    /**
     * 删除数据

     * @return 删除是否成功
     */
    @ApiOperation("删除单个数据")
    @PostMapping("/delete")
    public R delete(WlManager wlManager) {
        this.wlManagerService.delete(wlManager);
        return R.ok("删除成功");
    }
    @ApiOperation("批量删除货物")
    @PostMapping("/deletes")
    public R deletesById(@RequestBody List<WlManager>wlManagers) {
        int deletes = wlManagerService.deletes(wlManagers);
        return R.ok( deletes,"批量删除成功删除",null);
    }
    @ApiOperation("模糊查询")
    @RequestMapping(value = "/querybyLike",method = RequestMethod.POST)
    public R querybyLike(@ApiParam(name = "wlManager")  WlManager wlManager) {
        List<WlManager> wlManagers = wlManagerService.queryByLike(wlManager);
        return R.ok("查询成功",wlManagers);
    }

}

